import { constants }from './index';
import axios from 'axios';
import { fromJS } from 'immutable'

const changeList = (data)=>({
  type:constants.CHANGE_LIST,
  data: fromJS(data),
  totalPage: Math.ceil(data.length / 10)
})

export const searchFocus = ()=>({
  type: constants.SEARCH_FOCUSE
});

export const searchBlur = ()=>({
  type: constants.SEARCH_BLUR
});

export const getList = ()=>{
  return (dispatch) => {
    axios
      .get('/api/headerList.json')
      .then((res)=>{
        const data = res.data
        dispatch(changeList(data.data))
      })
      .catch(err=>{
      console.log(err)
    })
  }
};

export const mouseEnter = ()=>({
  type: constants.MOUNSE_ENTER
});

export const mouseLeave = ()=>({
  type: constants.MOUNSE_LEAVE
});

export const changePage = (page)=>({
  type: constants.CHANGE_PAGE,
  page
});